<template>
	<view class="container">
		<u-form :model="form" ref="uForm"  :error-type="['toast']" label-width="200">
			<u-form-item label="身高" prop="height">
				<u-input v-model="form.height" type="digit"/>
			</u-form-item>
			<u-form-item label="体重" prop="weight">
				<u-input v-model="form.weight" type="digit"/>
			</u-form-item>
			<u-form-item label="坐位体前屈(cm)" prop="v1">
				<u-input v-model="form.v1" type="digit"/>
			</u-form-item>
			<u-form-item label="立定跳远(cm)" prop="v2">
				<u-input v-model="form.v2" type="digit"/>
			</u-form-item>
			<u-form-item label="网球掷远(m)" prop="v3">
				<u-input v-model="form.v3" type="digit"/>
			</u-form-item>
			<u-form-item label="双脚连续跳(s)" prop="v4">
				<u-input v-model="form.v4" type="digit"/>
			</u-form-item>
			<u-form-item label="10米折返跑(s)" prop="v5">
				<u-input v-model="form.v5" type="digit"/>
			</u-form-item>
			<u-form-item label="走平衡木(s)" prop="v6">
				<u-input v-model="form.v6" type="digit"/>
			</u-form-item>
		</u-form>
		<u-button class="action-view" @click="saveClick">保存</u-button>
	</view>
</template>

<script>
	import { addReport } from '@/api/evaluate.js'
	export default {
		data() {
			return {
				form: {
					height: '',
					weight: '',
					v1: '',
					v2: '',
					v3: '',
					v4: '',
					v5: '',
					v6: '',
				},
				rules: {
					height: [{
						required: true,
						message: '请输入身高',
					}, ],
					weight: [{
						required: true,
						message: '请输入体重',
					}, ],
					v1: [{
						required: true,
						message: '请输入坐位体前屈',
					}, ],
					v1: [{
						required: true,
						message: '请输入立定跳远',
					}, ],
					v3: [{
						required: true,
						message: '请输入网球掷远',
					}, ],
					v4: [{
						required: true,
						message: '请输入双脚连续跳',
					}, ],
					v5: [{
						required: true,
						message: '请输入10米折返跑',
					}, ],
					v6: [{
						required: true,
						message: '请输入走平衡木',
					}, ],
				}
			}
		},
		onLoad(options) {
			this.childrenId = options.childrenId;
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			saveClick() {
				this.$refs.uForm.validate(valid => {
					console.log(valid);
					if (valid) {
						this.addRecord();
						return;
					}
				});
			},
			
			addRecord() {
				const data = [this.form.height,this.form.weight,this.form.v1,this.form.v2,this.form.v3,this.form.v4,this.form.v5,this.form.v6];
				const params = {
					childrenId: this.childrenId,
					values: JSON.stringify(data)
				}
				addReport(params).then(res => {
					console.log(res)
					uni.redirectTo({
						url: '/pages_evaluate/physicle/evaluate-report?evaluateRecordId=' + res.data.id
					})
				})
			}
		},
	}
</script>

<style lang="scss">
	page {
		background-color: $app-page-bg-color;
	}
</style>
<style lang="scss">
	@import '@/css/u-form.scss';
	
	.container {
		padding-left: 30rpx;
		padding-right: 30rpx;
		display: flex;
		flex-direction: column;
	}

	.children-view {
		width: 10rpx;
		flex: 1;
		display: flex;
		flex-direction: row;
	}

	.action-view1 {
		margin-top: 160rpx;
	}
</style>